import handler from "./action.ts";

const reducre = function (
  state = { ...handler.state },
  { type, val }: { type: string; val: any }
) {
  let newState = JSON.parse(JSON.stringify(state));
  let keys = Object.keys(handler.action);
  for (var i = 0; i < keys.length; i++) {
    if (keys[i] === type) {
      handler.action[type](newState, val);
    }
  }

  return newState;
};

export default reducre;
